while ($true) 
{
	$x = get-netadapter Wi-Fi 
	$disconnected = $false
	if ($x.MediaConnectionState -ne "Connected")
	{
		$d = Get-Date
		Write-Host $d " Disconnect was detected. Reconnecting ..."
		$disconnected = $true
	}

	else
	{
		if ((ping robofile)[4] -eq ' ' -or (ping robofile)[4].Split()[0] -ne "Reply")
		{
			$d = Get-Date
			Write-Host $d " Ping failure was detected. Reconnecting ..."
			$disconnected = $true
		}
	}

	if ($disconnected)
	{ 
		netsh wlan disconnect
		netsh wlan connect name="A-MSFTWLAN"    
		sleep(30)
	}
	sleep(10)
}
